<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="80px"
    >
      <el-form-item label="人才姓名" prop="talentName">
        <el-input
          v-model="dataForm.talentName"
          placeholder="人才姓名"
        ></el-input>
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-input v-model="dataForm.sex" placeholder="性别"></el-input>
      </el-form-item>
      <el-form-item label="研究领域" prop="studyDirection">
        <el-input
          v-model="dataForm.studyDirection"
          placeholder="研究领域"
        ></el-input>
      </el-form-item>
      <el-form-item label="引进方向" prop="intorducePerson">
        <el-input
          v-model="dataForm.intorducePerson"
          placeholder="引进方向"
        ></el-input>
      </el-form-item>
      <el-form-item label="人才合作意向" prop="cooperationPurpose">
        <el-input
          v-model="dataForm.cooperationPurpose"
          placeholder="人才合作意向"
        ></el-input>
      </el-form-item>
      <el-form-item label="特派员位置" prop="location">
        <el-input
          v-model="dataForm.location"
          placeholder="特派员位置"
        ></el-input>
      </el-form-item>
      <el-form-item label="特派员类型" prop="specialType">
        <el-input
          v-model="dataForm.specialType"
          placeholder="特派员类型"
        ></el-input>
      </el-form-item>
      <el-form-item label="联系方式" prop="telephone">
        <el-input
          v-model="dataForm.telephone"
          placeholder="联系方式"
        ></el-input>
      </el-form-item>
      <el-form-item label="服务领域" prop="rangeServices">
        <el-input
          v-model="dataForm.rangeServices"
          placeholder="服务领域"
        ></el-input>
      </el-form-item>
      <el-form-item label="事务信息" prop="affairsInformation">
        <el-input
          v-model="dataForm.affairsInformation"
          placeholder="事务信息"
        ></el-input>
      </el-form-item>
      <el-form-item label="工作单位" prop="companyAdress">
        <el-input
          v-model="dataForm.companyAdress"
          placeholder="工作单位"
        ></el-input>
      </el-form-item>
      <el-form-item label="任教学科" prop="educationSubject">
        <el-input
          v-model="dataForm.educationSubject"
          placeholder="任教学科"
        ></el-input>
      </el-form-item>
      <el-form-item label="文件数量" prop="fileNumber">
        <el-input
          v-model="dataForm.fileNumber"
          placeholder="文件数量"
        ></el-input>
      </el-form-item>

      <el-form-item label="图片id" prop="imageId">
        <el-input v-model="dataForm.imageId" placeholder="图片id"></el-input>
      </el-form-item>
      <el-form-item label="维修等级" prop="maintainGrade">
        <el-input
          v-model="dataForm.maintainGrade"
          placeholder="维修等级"
        ></el-input> </el-form-item
      ><el-form-item label="维修范围" prop="maintainRange">
        <el-input
          v-model="dataForm.maintainRange"
          placeholder="维修范围"
        ></el-input>
      </el-form-item>
      <el-form-item label="维修类别" prop="maintainType">
        <el-input
          v-model="dataForm.maintainType"
          placeholder="维修类别"
        ></el-input>
      </el-form-item>
      <el-form-item label="经营场所" prop="manageAdress">
        <el-input
          v-model="dataForm.manageAdress"
          placeholder="经营场所"
        ></el-input>
      </el-form-item>
      <el-form-item label="负责人" prop="principal">
        <el-input v-model="dataForm.principal" placeholder="负责人"></el-input>
      </el-form-item>
      <el-form-item label="人才类型id" prop="telentTypeId">
        <el-input
          v-model="dataForm.telentTypeId"
          placeholder="人才类型id"
        ></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      dataForm: {
        id: 0,
        talentName: "",
        sex: "",
        studyDirection: "",
        intorducePerson: "",
        cooperationPurpose: "",
        location: "",
        specialType: "",
        telephone: "",
        rangeServices: "",
        affairsInformation: "",
        companyAdress:"",
        educationSubiect: "",
        fileNumber: "",
        imageId:"",
        maintainGrade: "",
        maintainRange:"",
        maintainType: "",
        manageAdress: "",
        principal: "",
        telentTypeId: ""
      },
      dataRule: {
        talentName: [
          { required: true, message: "人才姓名不能为空", trigger: "blur" }
        ],
        sex: [{ required: true, message: "性别不能为空", trigger: "blur" }],
        studyDirection: [
          { required: true, message: "研究领域不能为空", trigger: "blur" }
        ],
        intorducePerson: [
          { required: true, message: "引进方向不能为空", trigger: "blur" }
        ],
        cooperationPurpose: [
          { required: true, message: "人才合作意向不能为空", trigger: "blur" }
        ],
        location: [
          { required: true, message: "特派员位置不能为空", trigger: "blur" }
        ],
        specialType: [
          { required: true, message: "特派员类型不能为空", trigger: "blur" }
        ],
        telephone: [
          { required: true, message: "联系方式不能为空", trigger: "blur" }
        ],
        rangeServices: [
          { required: true, message: "服务领域不能为空", trigger: "blur" }
        ],
        affairsInformation: [
          { required: true, message: "事务信息不能为空", trigger: "blur" }
        ],
        companyAdress:[
          {required:true,message:"工作单位不能为空 ",trigger:"blur"}
        ],
       educationSubiect: [
          { required: true, message: "任教学科不能为空", trigger: "blur" }
        ],
       fileNumber: [
          { required: true, message: "文件数量不能为空", trigger: "blur" }
        ],
       imageId: [
          { required: true, message: "图片id不能为空", trigger: "blur" }
        ],
        maintainGrade: [
          { required: true, message: "维修等级不能为空", trigger: "blur" }
        ],
        maintainRange: [
          { required: true, message: "维修范围不能为空", trigger: "blur" }
        ],
        maintainType: [
          { required: true, message: "维修类别不能为空", trigger: "blur" }
        ],
        manageAdress: [
          { required: true, message: "经营场所不能为空", trigger: "blur" }
        ],
        principal: [
          { required: true, message: "负责人不能为空", trigger: "blur" }
        ],
        telentTypeId: [
          { required: true, message: "人才类型id不能为空", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0;
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].resetFields();
        if (this.dataForm.id) {
          this.$http({
            url: this.$http.adornUrl(`/rencai/talent/delete`),
            method: "post",
            params: this.$http.adornParams()
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.dataForm.talentName = data.supply.talentName;
              this.dataForm.sex = data.supply.sex;
              this.dataForm.studyDirection = data.supply.studyDirection;
              this.dataForm.intorducePerson = data.supply.intorducePerson;
              this.dataForm.cooperationPurpose = data.supply.cooperationPurpose;
              this.dataForm.location = data.supply.location;
              this.dataForm.specialType = data.supply.specialType;
              this.dataForm.telephone = data.supply.telephone;
              this.dataForm.rangeServices = data.supply.rangeServices;
              this.dataForm.affairsInformation=data.supply.affairsInformation;
              this.dataForm.companyAdress=data.supply.companyAdress;
              this.dataForm.educationSubiect=data.supply.educationSubiect;
              this.dataForm.fileNumber=data.supply.fileNumber;
              this.dataForm.imageId=data.supply.imageId;
              this.dataForm.maintainGrade=data.supply.maintainGrade;
              this.dataForm.maintainRange=data.supply.maintainRange;
              this.dataForm.maintainType=data.supply.maintainType;
              this.dataForm.manageAdress=data.supply.manageAdress;
              this.dataForm.principal=data.supply.principal;
              this.dataForm.telentTypeId=data.supply.telentTypeId;
            }
          });
        }
      });
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(
              `/rencai/talent/${!this.dataForm.id ? "save" : "update"}`
            ),
            method: "post",
            data: this.$http.adornData({
              id: this.dataForm.id || undefined,
              talentName: this.dataForm.talentName,
              sex: this.dataForm.sex,
              studyDirection: this.dataForm.studyDirection,
              intorducePerson: this.dataForm.intorducePerson,
              cooperationPurpose: this.dataForm.cooperationPurpose,
              location: this.dataForm.location,
              specialType: this.dataForm.specialType,
              telephone: this.dataForm.telephone,
              rangeServices: this.dataForm.rangeServices,
              affairsInformation:this.dataForm.affairsInformation,
              companyAdress:this.dataForm.companyAdress,
              educationSubject:this.dataForm.educationSubject,
              fileNumber:this.dataForm.fileNumber,
              imageId:this.dataForm.imageId,
              maintainGrade:this.dataForm.maintainGrade,
              maintainRange:this.dataForm.maintainRange,
              maintainType:this.dataForm.maintainType,
              manageAdress:this.dataForm.manageAdress,
              principal:this.dataForm.principal,
              telentTypeId:this.dataForm.telentTypeId,
            })
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: "操作成功",
                type: "success",

                onClose: () => {
                  this.visible = false;
                  this.$emit("refreshDataList");
                }
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        }
      });
    }
  }
};
</script>
